#include"processbar.h"

const char* lable ="|/-\\";


//version1
void process()
{
    char buff[N];
    memset(buff,'\0',sizeof(buff));
    int n = strlen(lable);
    int cnt = 0;
    buff[0]= Head;
    while(cnt<=100)
    {
    
        printf("[%-100s][%3d%%][%c]\r",buff,cnt,lable[cnt%n]);
        fflush(stdout);

        buff[cnt++] = Body;
        if(cnt<100) buff[cnt] = Head;
        usleep(50000);
    }
    printf("\n");
}

char buff[N]={0};
//version2
void process_flush(double rate)
{
    int n = strlen(lable);
    static int cnt = 0;
    
    if(rate<=1.0) buff[0]= Head;
    printf("[\033[0;32;44m%-100s\033[0m][%.1f%%][%c]\r",buff,rate,lable[cnt%n]);
    fflush(stdout);

    buff[(int)rate] = Body;
    if((int)rate+1<100) buff[(int)rate+1] = Head;
    if(rate>=100.0) printf("\n");

    cnt++;
    cnt%=n;

}
